﻿using System.Linq;
using Microsoft.FxCop.Sdk;
using LINQtoFxCop.Core;

namespace LINQtoFxCop.Flaws.Implementation
{
  internal static class ImplementationExtenders
  {
    public static bool CreatesNewType(this Method method, string typeFullName)
    {
      return
        (
          from instruction in method.Instructions.Cast<Instruction>()
          where instruction.OpCode == OpCode.Newobj &&
                instruction.Value is InstanceInitializer &&
                (instruction.Value as InstanceInitializer).DeclaringType.IsSubTypeOf(typeFullName)
          select instruction
        ).HasItem();
    }
  }
}